﻿using CommonLib;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace YouErYuanBLL
{
    public class ChaKanSettingBLL
    {
        /// <summary>
        /// 分页查询幼儿园班级记录
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="youErYuanName">幼儿园班级名称</param>
        /// <param name="total">条件查询总记录数</param>
        /// <returns></returns>
        public object ChaKanSettingPageList(int pageIndex, int pageSize, string schoolid, out int total)
        {
            string where = "";
            if (string.IsNullOrEmpty(schoolid) == false)
            {
                schoolid = SqlFilter.Filter(schoolid);
                where = " schoolid = '" + schoolid + "'";
            }
            DataTable dt = SQLHepler.GetPaging("[qvEndDate] desc", "[V_classInfo]", where, pageIndex, pageSize, out total);
            return dt;
        }

        /// <summary>
        /// 班级所有学生记录
        /// </summary>
        /// <param name="youErYuanName">幼儿园班级id</param>
        /// <param name="total">条件查询总记录数</param>
        /// <returns></returns>
        public object ChaKanClassList(string classid)
        {
            string sql = "SELECT [studentId],[studentNo],[sex],[stuName],[bornDate],[mingZu],[jiGuan],[email],[classId],[headImgURL],[schoolId],[classMC],[jzname],[guanxi],[phone],[jzId],[password] FROM [dbo].[V_STUDENT] where [classId]=@classId order by [sDateYMD000] desc";
            SqlParameter[] parames =
            {
                new SqlParameter("@classId",classid)
            };
            DataTable dt = SQLHepler.GetDataTable(sql, parames);
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    var item = dt.Rows[i];
                    string pwd = item["password"].GetType() == typeof(System.DBNull) ? "" : Convert.ToString(item["password"]);
                    string pwd_jm = string.Empty;
                    //解码
                    try
                    {
                        pwd_jm = DESencodingTxt.DESDecoding(pwd);
                    }
                    catch (Exception)
                    {
                        pwd_jm = "123456";
                    }
                    dt.Rows[i]["password"] = pwd_jm;
                }
            }
            return dt;
        }

    }
}
